package com.briup.estore.adminAPI.web.controller;

import com.briup.estore.common.bean.User;
import com.briup.estore.common.service.IUserService;
import com.briup.estore.common.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;


/**
 * @author adam
 * @date 2022/10/11
 */
@Api(tags = "用户管理")
@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {
    @Autowired
    private IUserService userService;

    @ApiOperation("查询所有用户信息")
    @GetMapping("/findUserInfo")
    public Result findAll(@RequestParam(defaultValue = "", required = false) String query, Integer pageNum, Integer pageSize) {

        Page<User> userPage = null;
        try {
            userPage = userService.findAll(query, pageNum, pageSize);
            return Result.success(userPage);
        } catch (Exception e) {
            return Result.error(800, e.getMessage());
        }

    }

    @DeleteMapping("disable/{id}")
    public Result disable(@PathVariable Integer id) {

        userService.disable(id);
        return Result.success();
    }

    @PutMapping("enable/{id}")
    public Result enable(@PathVariable Long id) {
        userService.enable(id);
        return Result.success();
    }
}
